package org.objectsearch.web.tools;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author Carlos
 * 
 */
public class FormatDateTool {

	/**
	 * formatea la fecha y la convierte a string
	 * 
	 * @param date
	 *            fecha a formatear a string
	 * @return string conteniendo la hora formateada
	 */
	public static String formatDate(Date date) {
		if (date == null) {
			return null;
		}
		ObjectXmlConfigurationEnviroment enviroment = null;
		enviroment = ObjectXmlConfigurationEnviroment.getInstance();
		String dateFormat = null;
		try {
			Properties props = enviroment.getApplicationProperties();
			dateFormat = props.getProperty("date.format");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		if (dateFormat == null) {
			dateFormat = "dd/MM/yyyyy";
		}
		// System.out.println(dateFormat);
		SimpleDateFormat formatter = null;
		Locale locale = Locale.getDefault();
		formatter = new SimpleDateFormat(dateFormat, locale);
		String result = formatter.format(date);
		return result;
	}

}
